package org.ljj.xml.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ljj.model.UserModel;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class RegisterSimpleFormController extends SimpleFormController {
	public RegisterSimpleFormController(){
		//设置命令对象实现类  
		setCommandClass(UserModel.class);
		//设置命令对象的名字 
		setCommandName("user");
	}
	
	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		UserModel user = new UserModel();
		user.setUsername("liking");
		return user;
	}
	
	@Override
	protected Map referenceData(HttpServletRequest request) throws Exception {
		Map map = new HashMap();
		map.put("cityList", Arrays.asList("山东", "北京", "上海"));  
		return map;
	}
	
	@Override
	protected void doSubmitAction(Object command) throws Exception {
		UserModel user = (UserModel)command;
		//调用service层
		System.out.println(user);
	}
	
	
	
	@Override
	protected ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse response, BindException errors)
			throws Exception {
		ModelAndView mv = new ModelAndView();
		System.out.println("register UI ");
		mv.setViewName("register");
		return super.showForm(request, response, errors);
	}
}
